<template>
    <div>
        <el-row :gutter="20">
            <el-col :span="8">
                <el-card shadow="hover" class="mgb20" style="height:252px;">
                    <div class="user-info">
                        <img src="../../assets/img/photo.jpg" class="user-avator" alt />
                        <div class="user-info-cont">
                            <div class="user-info-name">{{name}}</div>
                            <div>{{roleName}}</div>
                        </div>
                    </div>
                    <div class="user-info-list">
                        上次登录时间：
                        <span>2019-11-01</span>
                    </div>
                    <div class="user-info-list">
                        上次登录地点：
                        <span>太原市:英才汇硕公司</span>
                    </div>
                </el-card>
                <el-card shadow="hover" style="height:212px;">
                    <div slot="header" class="clearfix">
                        <span>案件更新</span>
                    </div>
                    <el-progress :percentage="20" color="#315C8AFF"></el-progress>行政案件
                    <el-progress :percentage="50" color="#2C6E34FF"></el-progress>经济纠纷
                    <el-progress :percentage="80"></el-progress>民事案件
                    <el-progress :percentage="40" color="#9B4434FF"></el-progress>
                </el-card>
            </el-col>
            <el-col :span="16">
                <el-row :gutter="20" class="mgb20">
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{padding: '0px'}">
                            <div class="grid-content grid-con-1">
                                <i class="el-icon-lx-people grid-con-icon"></i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">2</div>
                                    <div>新增律师</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{padding: '0px'}">
                            <div class="grid-content grid-con-2">
                                <i class="el-icon-lx-notice grid-con-icon"></i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">11</div>
                                    <div>今日办案</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{padding: '0px'}">
                            <div class="grid-content grid-con-3">
                                <i class="el-icon-lx-goods grid-con-icon"></i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">5000</div>
                                    <div>访问人数</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                </el-row>


                <el-card shadow="hover" style="height:360px;">
                    <el-carousel :interval="4000" type="card" height="280px" style='margin-top: 20px'>
                        <el-carousel-item v-for="item in imgList" :key="item.id">
                            <img :src="item.url" width="100%" height="100%" alt="">
                        </el-carousel-item>
                    </el-carousel>
                </el-card>


            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="12">
                <el-card shadow="hover">
<!--                    <schart ref="bar" class="schart" canvasId="bar" :options="options"></schart>-->
                    <div ref="mains" style="width: 100%;height: 300px"></div>
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card shadow="hover">
                    <el-card shadow="hover" style="height:300px;">
                        <div ref="main2"  style="width: 100%;height: 300px"></div>
                    </el-card>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import * as echarts from 'echarts';
import { getRoleName } from '../../api/role'
let user = JSON.parse(localStorage.getItem('ms_username'));
export default {
    name: 'dashboard',
    data() {
        return {
            imgList: [
                {
                    id: '1',
                    url: require('../../assets/img/img1.jpg')
                },
                {
                    id: '2',
                    url: require('../../assets/img/img2.jpg')
                },
                {
                    id: '3',
                    url: require('../../assets/img/img3.jpg')
                },
                {
                    id: '4',
                    url: require('../../assets/img/img4.jpg')
                },
                {
                    id: '5',
                    url: require('../../assets/img/img5.jpg')
                }
            ],
            chartInstance: null,
            chartInstance2:null,
            name:user.userName,
            roleName:"",
            data: [
                {
                    name: '2018/09/04',
                    value: 1083
                },
                {
                    name: '2018/09/05',
                    value: 941
                },
                {
                    name: '2018/09/06',
                    value: 1139
                },
                {
                    name: '2018/09/07',
                    value: 816
                },
                {
                    name: '2018/09/08',
                    value: 327
                },
                {
                    name: '2018/09/09',
                    value: 228
                },
                {
                    name: '2018/09/10',
                    value: 1065
                }
            ],
        };
    },
    computed: {
    },
    mounted() {
        this.initEcharts()
    },
    created() {
        console.log(user.userId);
        getRoleName(user.userId).then(res=>{
            console.log(res);
            if(res.code==200) {
                this.roleName = res.data
            }
        })
    },
    methods: {
        getImageUrl(index) {
            switch (index) {
                case 1:
                    return '../../assets/img/img1.jpg';
                case 2:
                    return '../../assets/img/img2.jpg';
                case 3:
                    return '../../assets/img/img3.jpg';
                case 4:
                    return '../../assets/img/img4.jpg';
                case 5:
                    return '../../assets/img/img5.jpg';
                default:
                    return '';
            }
        },
        initEcharts() {
            this.chartInstance = this.$echarts.init(this.$refs.mains);
            this. chartInstance2= this.$echarts.init(this.$refs.main2)
            const option = {title: {
                    text: '律师工作时间分布'
                },
                tooltip: {
                    trigger: 'axis'
                },
                xAxis: {
                    type: 'category',
                    data: ['上午', '下午', '晚上']
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        name: '工作时长',
                        type: 'line',
                        data: [5, 3, 2]
                    }

                ]
            };
            const option2 = {
                title: {
                    text: '客户满意度统计'
                },
                tooltip: {},
                xAxis: {
                    type: 'category',
                    data: ['律师 A', '律师 B', '律师 C', '律师 D', '律师 E']
                },
                yAxis: {
                    type: 'value',
                    max: 100
                },
                series: [
                    {
                        name: '满意度',
                        type: 'bar',
                        data: [80, 90, 75,20,30]
                    }
                ]
            }
            this.chartInstance.setOption(option)
            this.chartInstance2.setOption(option2)
        }

    },
};
</script>


<style scoped>
.el-row {
    margin-bottom: 20px;
}

.grid-content {
    display: flex;
    align-items: center;
    height: 100px;
}

.grid-cont-right {
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: #999;
}

.grid-num {
    font-size: 30px;
    font-weight: bold;
}

.grid-con-icon {
    font-size: 50px;
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    color: #fff;
}

.grid-con-1 .grid-con-icon {
    background: rgb(49, 92, 138);
}

.grid-con-1 .grid-num {
    color: rgb(43, 87, 133);
}

.grid-con-2 .grid-con-icon {
    background: rgb(44, 110, 52);
}

.grid-con-2 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
    background: rgb(155, 68, 52);
}

.grid-con-3 .grid-num {
    color: rgb(242, 94, 67);
}

.user-info {
    display: flex;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid #ccc;
    margin-bottom: 20px;
}

.user-avator {
    width: 120px;
    height: 120px;
    border-radius: 50%;
}

.user-info-cont {
    padding-left: 50px;
    flex: 1;
    font-size: 14px;
    color: #999;
}

.user-info-cont div:first-child {
    font-size: 30px;
    color: #222;
}

.user-info-list {
    font-size: 14px;
    color: #999;
    line-height: 25px;
}

.user-info-list span {
    margin-left: 70px;
}

.mgb20 {
    margin-bottom: 20px;
}

.todo-item {
    font-size: 14px;
}

.todo-item-del {
    text-decoration: line-through;
    color: #999;
}

.el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 200px;
    margin: 0;
}

.el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
}
</style>
